#include "common.h"
#include "Literal.h"
#include "Integer.h"
#include "Real.h"

#include <stdint.h>
using std::to_string;

TokenExtractor Integer::extractor = TokenExtractor([](char in){
	return isdigit(in) || in == '-';
}, [](char first, ifstream& rest)->Token*{
	string builder;
	bool real = false;
	
	do
	{
		builder += first;
		first = rest.get();
		if(first == 'e' || first == 'E' || first == '.') real = true;
	}
	while(isdigit(first) || first == '-' || first == 'e' || first == 'E' || first == '.');

	rest.unget();

	if(real) return new Real(builder);
	return new Integer(builder);
});

string Integer::print() const
{
	return to_string(value);
}

string Integer::printType() const
{
	return "<INTEGER>";
}
